#include "stdafx.h"
#include "SurfaceInsp.h"

#include "SurfaceInspDoc.h"
#include "SurfaceInspView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static const CString strInfo = 
	_T("This sample illustrates how to switch between multiple views on a single document in a SDI application\r\n\r\nView 1");

/////////////////////////////////////////////////////////////////////////////
// CSurfaceInspView

IMPLEMENT_DYNCREATE(CSurfaceInspView, CView)

BEGIN_MESSAGE_MAP(CSurfaceInspView, CView)
	ON_WM_CONTEXTMENU()
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSurfaceInspView construction/destruction

CSurfaceInspView::CSurfaceInspView()
{
	// TODO: add construction code here

}

CSurfaceInspView::~CSurfaceInspView()
{
}

BOOL CSurfaceInspView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSurfaceInspView drawing

void CSurfaceInspView::OnDraw(CDC* pDC)
{
//	CSurfaceInspDoc* pDoc = GetDocument();
//	ASSERT_VALID(pDoc);

	const int iOffset = 20;

	CFont* pFontOld = (CFont*) pDC->SelectStockObject (DEFAULT_GUI_FONT);
	ASSERT (pFontOld != NULL);

	CRect rectClient;
	GetClientRect (&rectClient);

	CRect rectText = rectClient;
	rectText.DeflateRect (iOffset, iOffset);
	pDC->DrawText (strInfo, rectText, DT_CALCRECT | DT_WORDBREAK);

	rectText.OffsetRect (	(rectClient.Width () - rectText.Width () - 2 * iOffset) / 2,
							(rectClient.Height () - rectText.Height () - 2 * iOffset) / 2);

	CRect rectFrame = rectText;
	rectFrame.InflateRect (iOffset, iOffset);

	CDrawingManager dm (*pDC);

	dm.FillGradient2 (rectFrame, RGB (246, 241, 178), RGB (234, 223, 67), 35);

	pDC->Draw3dRect (rectFrame, RGB (168, 158, 18), RGB (168, 158, 18));

	pDC->SetBkMode (TRANSPARENT);
	pDC->SetTextColor (0);
	pDC->DrawText (strInfo, rectText, DT_WORDBREAK);
	pDC->SelectObject (pFontOld);
}

/////////////////////////////////////////////////////////////////////////////
// CSurfaceInspView printing

void CSurfaceInspView::OnFilePrintPreview() 
{
	AFXPrintPreview (this);
}

BOOL CSurfaceInspView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSurfaceInspView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CSurfaceInspView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CSurfaceInspView diagnostics

#ifdef _DEBUG
void CSurfaceInspView::AssertValid() const
{
	CView::AssertValid();
}

void CSurfaceInspView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CSurfaceInspDoc* CSurfaceInspView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSurfaceInspDoc)));
	return (CSurfaceInspDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSurfaceInspView message handlers

void CSurfaceInspView::OnContextMenu(CWnd*, CPoint point)
{
	theApp.ShowPopupMenu (IDR_CONTEXT_MENU, point, this);
}

